package com.enterprise.dao.impl;

import com.enterprise.dao.BaseDao;
import com.enterprise.dao.RoleDao;
import com.enterprise.entity.Role;
import com.enterprise.entity.page.PageModel;
import com.enterprise.util.DaoUtils;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository("roleDao")
public class RoleDaoImpl implements RoleDao {

	@Resource
	private BaseDao dao;

	public void setDao(BaseDao dao) {
		this.dao = dao;
	}

	@Override
	public int insert(Role role) {
		Object roleid= dao.selectOne("resources.getRoleid");
		role.setRoleid(DaoUtils.getMaxId(roleid));
		return dao.insert("role.insert", role);
	}

	@Override
	public int delete(Role role) {
		return dao.delete("role.delete", role);
	}

	@Override
	public int update(Role role) {
		return dao.update("role.update", role);
	}

	@Override
	public Role selectOne(Role role) {
		return (Role) dao.selectOne("role.selectOne", role);
	}

	@Override
	public PageModel selectPageList(Role role) {
		return dao.selectPageList("role.selectPageList", "role.selectPageCount", role);
	}

	@Override
	public List<Role> selectList(Role role) {
		return dao.selectList("role.selectList", role);
	}

	@Override
	public int deleteById(int id) {
		return dao.delete("role.deleteById",id);
	}

	@Override
	public Role selectById(int id) {
		return (Role) dao.selectOne("role.selectById",id);
	}

	@Override
	public PageModel selectPowerPageList(Role role) {
		return dao.selectPageList("role.selectPowerPageList", "role.selectPageCount", role);
	}
}
